
public class Player {
	static int playerSpeed = 4;
	static int x = 128;
	static int y = 128;
	static boolean isMoving = false;
	public static void movePlayer(int e){
		if(isMoving == false){
			if(e ==87){
				y -= 32;
			}
			if(e ==68){
				x += 32;
				
			}
			if(e ==83){
				y += 32;
				
			}
			if(e ==65){
				x -= 32;
			}
			isMoving = true;
		}		
	}
	public static void checkPos(){
		if(Variables.cameraX+Variables.playerX >= 300){
			Variables.cameraX -= 1;
		}
		if(Variables.cameraX+Variables.playerX<= 300){
			Variables.cameraX += 1;
		}
		if(Variables.cameraY +Variables.playerY <= 200){
			Variables.cameraY += 1;
		}
		if(Variables.cameraY +Variables.playerY >= 200){
			Variables.cameraY -= 1;
		}
		
		if(isMoving == true){
			//////   If the next tile is a wall or door  //////////
			
			if(Variables.TileId[x/32][y/32] < 149 && Variables.TileId[x/32][y/32] >= 50){
				x = Variables.playerX;
				y = Variables.playerY;
			}	
			else if(Variables.TileId[x/32][y/32] < 50){
				System.out.println(x/32+"  "+y/32);

				Variables.playerX = x;
				Variables.playerY = y;
				isMoving = true;
				LevelArray.loadDoor();
			}
			
			
			//////////   Moves Camera   ////////////
			if(Variables.cameraX+x >= 472){
				Variables.cameraX -= playerSpeed-1;
			}
			if(Variables.cameraX+x <= 128){
				Variables.cameraX += playerSpeed-1;
			}
			if(Variables.cameraY + y <= 128){
				Variables.cameraY += playerSpeed-1;
			}
			if(Variables.cameraY + y >= 272){
				Variables.cameraY -= playerSpeed-1;
			}
			
			
			
			///// If the next tile is walkable then move  //////////////
			
			if(Variables.playerX < x){
				Variables.playerX += playerSpeed;
			}
			else if(Variables.playerX > x){
				Variables.playerX -= playerSpeed;
			}
			else if(Variables.playerY > y){
				Variables.playerY -= playerSpeed;
			}else if(Variables.playerY < y){
				Variables.playerY += playerSpeed;
			}
			else{
				isMoving = false;
			}
		}
	}
}
